package com.hundsun.cprs.yyt.service.trade.domain;

import java.util.Date;

import com.hundsun.cprs.yyt.common.base.DomainBase;
import com.hundsun.cprs.yyt.service.trade.enums.EnumEntustBSType;
import com.hundsun.cprs.yyt.service.trade.enums.EnumEntustFrom;
import com.hundsun.cprs.yyt.service.trade.enums.EnumEntustTag;
import com.hundsun.cprs.yyt.service.trade.enums.EnumTradeEntrustStatus;

public class TradeEntrust extends DomainBase{
    private Long id;

    /**
     * 关联订单编号
     */
    private String orderSn;

    /**
     * 委托编号
     */
    private Long entrustNo;

    /**
     * 用户ID
     */
    private Long userId;
    
    /**
     * 用户姓名
     */
    private String userName;

    /**
     * 资金账号
     */
    private String fundAccount;

    /**
     * 商品ID
     */
    private Long goodsId;

    /**
     * 商品代码
     */
    private String goodsCode;

    /**
     * 委托价格
     */
    private Long entrustPrice;
    
    /**
     * 委托方向：买，卖  {@link EnumEntustBSType}
     */
    private String entrustBs;
    
    /**
     * 委托单标签：新用户，老用户   {@link EnumEntustTag}
     */
    private Integer entrustTag; 

    /**
     * 委托数量
     */
    private Long entrustAmount;

    /**
     * 委托状态 {@link EnumTradeEntrustStatus}
     */
    private Integer entrustStatus;
    
    /**
     * 委托大类状态 {@link EnumTradeStatus}
     */
    private Integer status;

    /**
     * 上报时间
     */
    private Date entrustTime;
    
    /**
     * 已成数量：卖为负，买为正
     */
    private Long businessAmount;
    
    /** 
     * 资金已支出或已收入(卖为正数，买为负数)，排除佣金，综合管理费
     */
    private Long totalBusinessFund;// 总的

    /**
     * 总交易金额：卖为正，买为负
     */
    private Long businessFund;
    
    /**
     * 盈利金额：买为0，卖为[匹配价格-委卖价格]*N - 佣金 - 综合管理费]
     */
    private Long gainBusinessFund;

    /**
     * 佣金总额
     */
    private Long commissionFund;

    /**
     * 佣金扣除比例
     */
    private Integer commissionRate;

    /**
     * 综合管理费总额
     */
    private Long managementFund;

    /**
     * 综合管理费扣除比例
     */
    private Integer managementRate;
    
    /**
     *  委托单过期时间，到期后委托单撤单
     */
    private Date expireDate;
    
    /**
     * 备注信息
     */
    private String memo;
    
    /**
     * 委托单来源 {@link EnumEntustFrom}
     */
    private Integer entrustFrom;
    
    
    public boolean isBuy(){
        return EnumEntustBSType.BUY.getCode().toString().equals(getEntrustBs());
    }
    
    public boolean isSell(){
        return EnumEntustBSType.SELL.getCode().toString().equals(getEntrustBs());
    }
    
    public boolean isFromUser(){
        return EnumEntustFrom.FROM_USER.getCode() == getEntrustFrom();
    }
    
    public boolean isFromPlateform(){
        return EnumEntustFrom.FROM_PLATFORM.getCode() == getEntrustFrom();
    }
    
    /**
     * 是否委托的数量已经全部成交
     * 
     * @return
     */
    public boolean isEntrustAmountAllMatch() {
        return this.getSurplusEntrustAmount() == 0;
    }

    /**
     * 得到剩余未撮合的份额数量
     * 
     * @return
     */
    public Long getSurplusEntrustAmount() {
        return this.entrustAmount - Math.abs(this.businessAmount);
    }
    

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getOrderSn() {
        return orderSn;
    }

    public void setOrderSn(String orderSn) {
        this.orderSn = orderSn == null ? null : orderSn.trim();
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getFundAccount() {
        return fundAccount;
    }

    public void setFundAccount(String fundAccount) {
        this.fundAccount = fundAccount == null ? null : fundAccount.trim();
    }

    public Long getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(Long goodsId) {
        this.goodsId = goodsId;
    }

    public String getGoodsCode() {
        return goodsCode;
    }

    public void setGoodsCode(String goodsCode) {
        this.goodsCode = goodsCode == null ? null : goodsCode.trim();
    }

    public Long getEntrustPrice() {
        return entrustPrice;
    }

    public void setEntrustPrice(Long entrustPrice) {
        this.entrustPrice = entrustPrice;
    }

    public Long getEntrustAmount() {
        return entrustAmount;
    }

    public void setEntrustAmount(Long entrustAmount) {
        this.entrustAmount = entrustAmount;
    }

    public Integer getEntrustStatus() {
        return entrustStatus;
    }

    public void setEntrustStatus(Integer entrustStatus) {
        this.entrustStatus = entrustStatus;
    }

    public Date getEntrustTime() {
        return entrustTime;
    }

    public void setEntrustTime(Date entrustTime) {
        this.entrustTime = entrustTime;
    }

    public Long getCommissionFund() {
        return commissionFund;
    }

    public void setCommissionFund(Long commissionFund) {
        this.commissionFund = commissionFund;
    }

    public Integer getCommissionRate() {
        return commissionRate;
    }

    public void setCommissionRate(Integer commissionRate) {
        this.commissionRate = commissionRate;
    }

    public Long getManagementFund() {
        return managementFund;
    }

    public void setManagementFund(Long managementFund) {
        this.managementFund = managementFund;
    }

    public Integer getManagementRate() {
        return managementRate;
    }

    public void setManagementRate(Integer managementRate) {
        this.managementRate = managementRate;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getEntrustBs() {
        return entrustBs;
    }

    public void setEntrustBs(String entrustBs) {
        this.entrustBs = entrustBs;
    }

    public Long getEntrustNo() {
        return entrustNo;
    }

    public void setEntrustNo(Long entrustNo) {
        this.entrustNo = entrustNo;
    }

    public Long getBusinessAmount() {
        return businessAmount;
    }

    public void setBusinessAmount(Long businessAmount) {
        this.businessAmount = businessAmount;
    }

    public Integer getEntrustTag() {
        return entrustTag;
    }

    public void setEntrustTag(Integer entrustTag) {
        this.entrustTag = entrustTag;
    }

    public Long getTotalBusinessFund() {
        return totalBusinessFund;
    }

    public void setTotalBusinessFund(Long totalBusinessFund) {
        this.totalBusinessFund = totalBusinessFund;
    }

    public Long getBusinessFund() {
        return businessFund;
    }

    public void setBusinessFund(Long businessFund) {
        this.businessFund = businessFund;
    }

    public Long getGainBusinessFund() {
        return gainBusinessFund;
    }

    public void setGainBusinessFund(Long gainBusinessFund) {
        this.gainBusinessFund = gainBusinessFund;
    }

    public Date getExpireDate() {
        return expireDate;
    }

    public void setExpireDate(Date expireDate) {
        this.expireDate = expireDate;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMemo() {
        return memo;
    }

    public void setMemo(String memo) {
        this.memo = memo;
    }

    public Integer getEntrustFrom() {
        return entrustFrom;
    }

    public void setEntrustFrom(Integer entrustFrom) {
        this.entrustFrom = entrustFrom;
    }

    /**
     * 是否委托交易中
     * @return
     */
    public boolean isTrading(){
        return EnumTradeEntrustStatus.COMMITED.getStatus() == getStatus() || EnumTradeEntrustStatus.PART_DEALT.getStatus() == getStatus();

    }
}